---
title: "Untitled"
output: html_document
date: "2023-03-17"
---

############################################
Title: 4_04_Table_4.rmd
Purpose: This code runs the baseline aggregate level regressions in Table 4 
Last updated: 19-04-2024

Input:
    - Baseline macro data. Latest version: final_agg_macro_data_monthly.csv 

Output:
    - Table 4
  
##########################################




########################################## 
1. Setup
########################################## 

0. Setup *Set your file path here*
```{r, results="hide", include=FALSE}
#Clear user defined environment
rm(list=ls())

#Load packages
require(stargazer); require(lubridate); library(sandwich); library(ggplot2); require(dplyr); require(tidyverse); library(readxl); library(sandwich); library(lmtest); library(psych)
require(quantmod); require(dynlm); require(AER); require(vars); require(forecast); require(stargazer); require(strucchange); require(xts); require(lubridate); require(fGarch); require(zoo); require(timeSeries); library(sandwich); require(car);library(fBasics); library(ggplot2); require(dplyr); require(tidyverse); library(readxl); library(sandwich); library(QuantPsyc); library(tseries); library(latticeExtra); library(corrplot); library(psych) ; library(stringr); library(readr); library(see)

#options
options(digits=4)
options(stringsAsFactors = FALSE)
options(scipen=999)

#Assign dplyr verbs  
select <- dplyr::select
rename <- dplyr::rename
mutate <- dplyr::mutate
filter <- dplyr::filter
arrange <- dplyr::arrange
distinct <- dplyr::distinct
group_by <- dplyr::group_by
summarise <- dplyr::summarise
list <- base::list

#Define directories
global <- ".../2024_RFS_Replication_TOSUBMIT"

```

1.1 Load data
```{r, results="hide", include=FALSE}

final_agg_macro_data <- read_csv(paste0(global, "/Data/final_agg_macro_data_monthly.csv", ""), 
      col_types = cols(...1 = col_skip(), date = col_date(format = "%Y-%m-%d")))

```

1.2 Set sample period to use
```{r, results="hide", include=FALSE}

#Select sample period
macrofin_m_2000_extd = subset(final_agg_macro_data, date > "1999-11-01" & date < "2023-04-01")  

#Exclude GFC
macrofin_m_2000_extd_excrisis = subset(macrofin_m_2000_extd, date < "2007-12-01" | date > "2009-03-01") 


```



########################################## 
3. Table 4 results
##########################################

3.1 OLS Reg: Panel A - Private
```{r, include=FALSE, results='hide'}

mod_lip = lm(lip_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + lip_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lip = NeweyWest(lm(lip_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd  + first_pc_fd +  termspr + ffr_r  + lip_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lip, vcov = nw_mod_lip )
robust_mod_lip = coeftest(mod_lip, vcov = nw_mod_lip)[,3]
coef_mod_lip=lm.beta(mod_lip)



mod_ism_man = lm(ism_man_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_man = NeweyWest(lm(ism_man_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_man, vcov = nw_mod_ism_man )
robust_mod_ism_man = coeftest(mod_ism_man, vcov = nw_mod_ism_man)[,3]
coef_mod_ism_man=lm.beta(mod_ism_man)



mod_ism_nonman = lm(ism_nonman_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_nonman = NeweyWest(lm(ism_nonman_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman )
robust_mod_ism_nonman = coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman)[,3]
coef_mod_ism_nonman=lm.beta(mod_ism_nonman)



mod_tcu = lm(tcu_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_tcu = NeweyWest(lm(tcu_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_tcu, vcov = nw_mod_tcu )
robust_mod_tcu = coeftest(mod_tcu, vcov = nw_mod_tcu)[,3]
coef_mod_tcu=lm.beta(mod_tcu)




mod_lnew = lm(lnew_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lnew = NeweyWest(lm(lnew_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lnew, vcov = nw_mod_lnew )
robust_mod_lnew = coeftest(mod_lnew, vcov = nw_mod_lnew)[,3]
coef_mod_lnew=lm.beta(mod_lnew)




mod_linv = lm(linv_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_linv = NeweyWest(lm(linv_3m_ahead ~ agg_loan_spr_no_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_linv, vcov = nw_mod_linv )
robust_mod_linv = coeftest(mod_linv, vcov = nw_mod_linv)[,3]
coef_mod_linv=lm.beta(mod_linv)



stargazer(mod_lip, mod_tcu, mod_lnew, mod_linv, mod_ism_man, mod_ism_nonman, 
          type = "text", 
          align = TRUE, 
          #no.space = TRUE, 
          #dep.var.labels = c("coincident Index - 12m ahead"), 
          se = list(robust_mod_lip,  robust_mod_tcu, robust_mod_lnew, robust_mod_linv, robust_mod_ism_man, robust_mod_ism_nonman), 
          coef = list(coef_mod_lip,  coef_mod_tcu, coef_mod_lnew, coef_mod_linv, coef_mod_ism_man,  coef_mod_ism_nonman ),
          omit = c( "Constant", "lip_1m_behind","ism_man_1m_behind", "ism_nonman_1m_behind", "tcu_1m_behind", "lnew_1m_behind", "linv_1m_behind" )
          )


```

3.2 OLS Reg: Panel A - Public
```{r, include=FALSE, results='hide'}

mod_lip = lm(lip_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + lip_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lip = NeweyWest(lm(lip_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd  + first_pc_fd +  termspr + ffr_r  + lip_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lip, vcov = nw_mod_lip )
robust_mod_lip = coeftest(mod_lip, vcov = nw_mod_lip)[,3]
coef_mod_lip=lm.beta(mod_lip)




mod_ism_man = lm(ism_man_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_man = NeweyWest(lm(ism_man_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_man, vcov = nw_mod_ism_man )
robust_mod_ism_man = coeftest(mod_ism_man, vcov = nw_mod_ism_man)[,3]
coef_mod_ism_man=lm.beta(mod_ism_man)



mod_ism_nonman = lm(ism_nonman_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_nonman = NeweyWest(lm(ism_nonman_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman )
robust_mod_ism_nonman = coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman)[,3]
coef_mod_ism_nonman=lm.beta(mod_ism_nonman)



mod_tcu = lm(tcu_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_tcu = NeweyWest(lm(tcu_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_tcu, vcov = nw_mod_tcu )
robust_mod_tcu = coeftest(mod_tcu, vcov = nw_mod_tcu)[,3]
coef_mod_tcu=lm.beta(mod_tcu)




mod_lnew = lm(lnew_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lnew = NeweyWest(lm(lnew_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lnew, vcov = nw_mod_lnew )
robust_mod_lnew = coeftest(mod_lnew, vcov = nw_mod_lnew)[,3]
coef_mod_lnew=lm.beta(mod_lnew)




mod_linv = lm(linv_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_linv = NeweyWest(lm(linv_3m_ahead ~ agg_loan_spr_has_COMPUSTAT_assets_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_linv, vcov = nw_mod_linv )
robust_mod_linv = coeftest(mod_linv, vcov = nw_mod_linv)[,3]
coef_mod_linv=lm.beta(mod_linv)




stargazer(mod_lip, mod_tcu, mod_lnew, mod_linv, mod_ism_man, mod_ism_nonman, 
          type = "text", 
          align = TRUE, 
          #no.space = TRUE, 
          #dep.var.labels = c("coincident Index - 12m ahead"), 
          se = list(robust_mod_lip,  robust_mod_tcu, robust_mod_lnew, robust_mod_linv, robust_mod_ism_man, robust_mod_ism_nonman), 
          coef = list(coef_mod_lip,  coef_mod_tcu, coef_mod_lnew, coef_mod_linv, coef_mod_ism_man,  coef_mod_ism_nonman ),
          omit = c( "Constant", "lip_1m_behind","ism_man_1m_behind", "ism_nonman_1m_behind", "tcu_1m_behind", "lnew_1m_behind", "linv_1m_behind" )
          )


```

3.3 OLS Reg: Panel B - No Bond
```{r, include=FALSE, results='hide'}

mod_lip = lm(lip_3m_ahead ~ agg_loan_spr_no_bond_firm_fd  + first_pc_fd +  termspr + ffr_r  + lip_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lip = NeweyWest(lm(lip_3m_ahead ~ agg_loan_spr_no_bond_firm_fd  + first_pc_fd +  termspr + ffr_r  + lip_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lip, vcov = nw_mod_lip )
robust_mod_lip = coeftest(mod_lip, vcov = nw_mod_lip)[,3]
coef_mod_lip=lm.beta(mod_lip)



mod_ism_man = lm(ism_man_3m_ahead ~ agg_loan_spr_no_bond_firm_fd  + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_man = NeweyWest(lm(ism_man_3m_ahead ~ agg_loan_spr_no_bond_firm_fd  + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_man, vcov = nw_mod_ism_man )
robust_mod_ism_man = coeftest(mod_ism_man, vcov = nw_mod_ism_man)[,3]
coef_mod_ism_man=lm.beta(mod_ism_man)



mod_ism_nonman = lm(ism_nonman_3m_ahead ~ agg_loan_spr_no_bond_firm_fd  + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_nonman = NeweyWest(lm(ism_nonman_3m_ahead ~ agg_loan_spr_no_bond_firm_fd  + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman )
robust_mod_ism_nonman = coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman)[,3]
coef_mod_ism_nonman=lm.beta(mod_ism_nonman)




mod_tcu = lm(tcu_3m_ahead ~ agg_loan_spr_no_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_tcu = NeweyWest(lm(tcu_3m_ahead ~ agg_loan_spr_no_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_tcu, vcov = nw_mod_tcu )
robust_mod_tcu = coeftest(mod_tcu, vcov = nw_mod_tcu)[,3]
coef_mod_tcu=lm.beta(mod_tcu)



mod_lnew = lm(lnew_3m_ahead ~ agg_loan_spr_no_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lnew = NeweyWest(lm(lnew_3m_ahead ~ agg_loan_spr_no_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lnew, vcov = nw_mod_lnew )
robust_mod_lnew = coeftest(mod_lnew, vcov = nw_mod_lnew)[,3]
coef_mod_lnew=lm.beta(mod_lnew)




mod_linv = lm(linv_3m_ahead ~ agg_loan_spr_no_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_linv = NeweyWest(lm(linv_3m_ahead ~ agg_loan_spr_no_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_linv, vcov = nw_mod_linv )
robust_mod_linv = coeftest(mod_linv, vcov = nw_mod_linv)[,3]
coef_mod_linv=lm.beta(mod_linv)





stargazer(mod_lip, mod_tcu, mod_lnew, mod_linv, mod_ism_man, mod_ism_nonman, 
          type = "text", 
          align = TRUE, 
          #no.space = TRUE, 
          #dep.var.labels = c("coincident Index - 12m ahead"), 
          se = list(robust_mod_lip,  robust_mod_tcu, robust_mod_lnew, robust_mod_linv, robust_mod_ism_man, robust_mod_ism_nonman), 
          coef = list(coef_mod_lip,  coef_mod_tcu, coef_mod_lnew, coef_mod_linv, coef_mod_ism_man,  coef_mod_ism_nonman ),
          omit = c( "Constant", "lip_1m_behind","ism_man_1m_behind", "ism_nonman_1m_behind", "tcu_1m_behind", "lnew_1m_behind", "linv_1m_behind" )
          )



```

3.4 OLS Reg: Panel B - Bond
```{r, include=FALSE, results='hide'}

mod_lip = lm(lip_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + lip_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lip = NeweyWest(lm(lip_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + lip_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lip, vcov = nw_mod_lip )
robust_mod_lip = coeftest(mod_lip, vcov = nw_mod_lip)[,3]
coef_mod_lip=lm.beta(mod_lip)




mod_ism_man = lm(ism_man_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_man = NeweyWest(lm(ism_man_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + ism_man_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_man, vcov = nw_mod_ism_man )
robust_mod_ism_man = coeftest(mod_ism_man, vcov = nw_mod_ism_man)[,3]
coef_mod_ism_man=lm.beta(mod_ism_man)



mod_ism_nonman = lm(ism_nonman_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_nonman = NeweyWest(lm(ism_nonman_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + ism_nonman_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman )
robust_mod_ism_nonman = coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman)[,3]
coef_mod_ism_nonman=lm.beta(mod_ism_nonman)


mod_tcu = lm(tcu_3m_ahead ~ agg_loan_spr_bond_firm_fd  + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_tcu = NeweyWest(lm(tcu_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + tcu_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_tcu, vcov = nw_mod_tcu )
robust_mod_tcu = coeftest(mod_tcu, vcov = nw_mod_tcu)[,3]
coef_mod_tcu=lm.beta(mod_tcu)


mod_lnew = lm(lnew_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lnew = NeweyWest(lm(lnew_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + lnew_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lnew, vcov = nw_mod_lnew )
robust_mod_lnew = coeftest(mod_lnew, vcov = nw_mod_lnew)[,3]
coef_mod_lnew=lm.beta(mod_lnew)



mod_linv = lm(linv_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_linv = NeweyWest(lm(linv_3m_ahead ~ agg_loan_spr_bond_firm_fd + first_pc_fd +  termspr + ffr_r  + linv_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_linv, vcov = nw_mod_linv )
robust_mod_linv = coeftest(mod_linv, vcov = nw_mod_linv)[,3]
coef_mod_linv=lm.beta(mod_linv)



stargazer(mod_lip, mod_tcu, mod_lnew, mod_linv, mod_ism_man, mod_ism_nonman, 
          type = "text", 
          align = TRUE, 
          #no.space = TRUE, 
          #dep.var.labels = c("coincident Index - 12m ahead"), 
          se = list(robust_mod_lip,  robust_mod_tcu, robust_mod_lnew, robust_mod_linv, robust_mod_ism_man, robust_mod_ism_nonman), 
          coef = list(coef_mod_lip,  coef_mod_tcu, coef_mod_lnew, coef_mod_linv, coef_mod_ism_man,  coef_mod_ism_nonman ),
          omit = c( "Constant", "lip_1m_behind","ism_man_1m_behind", "ism_nonman_1m_behind", "tcu_1m_behind", "lnew_1m_behind", "linv_1m_behind" )
          )




```
